EN FR
EN FR


Section: New Results

AD adjoints and Dynamic Memory

Participants : Laurent Hascoët, Jean Utke [Argonne National Lab. (Illinois, USA)] .

Again in the adjoint mode, dynamic memory allocation and the associated pointer manipulations pose difficult problems. As the adjoint mode is bound to recover past values of variables, the need arises to recover past values of pointers too. However, these values are addresses often relative to some dynamically allocated memory. The original program often manages memory by allocating and deallocating memory on the run. Correspondingly, the adjoint program will have to reallocate memory as it walks backwards along the original allocation. If recovery of past values is implemented through storage, e.g. on a stack, the stored addresses refer to memory that has been deallocated, and do not correspond to the reallocated memory zones.

In 2011 we investigated this problem in two principal directions:

  • We may consider not storing the address, but rather recompute it by repeating in the reverse sweep its calculation from the forward sweep. This is not always possible as pointer assignment and manipulation may be complex and distributed in the code. However, when possible, it is certainly a very efficient approach. We propose an data-flow algorithm to detect applicable cases.

  • For the remaining cases where storage must be used, we study an address mapping mechanism, such that addresses inside some allocated memory can be dynamically converted into addresses inside the corresponding reallocated memory.